package com.qf.dao.impl;

import com.qf.dao.StuDao;
import com.qf.pojo.PageBean;
import com.qf.pojo.Stu;
import com.qf.service.StuService;
import com.qf.service.impl.StuServiceImpl;

import java.util.List;

public class StuDaoImpl implements StuDao {
    private StuService stuService=new StuServiceImpl();
    @Override
    public Stu login(String stuname, String pwd) {
        Stu login = stuService.login(stuname, pwd);
        if(login==null){
            throw new RuntimeException("用户不存在");
        }
        if(!login.getPwd().equalsIgnoreCase(pwd)){
            throw new RuntimeException("密码错误");
        }
        return login;
    }

    @Override
    public void addStu(Stu stu) {
        stuService.insertStu(stu);
    }

    @Override
    public List<Stu> findAll(int page_num, int page_size) {
        return stuService.selectAll(page_size,page_num);
    }

    @Override
    public void remove(int id) {
        stuService.delete(id);
    }

    @Override
    public void modiy(Stu stu) {
        stuService.update(stu);
    }

    @Override
    public PageBean<Stu> findByPage(int page_num, int page_size) {
        long totalSize=stuService.selectCount();
        List<Stu> data=stuService.selectByPage(page_num,page_size);
        PageBean<Stu> pageBean=new PageBean<Stu>(page_size,page_num,totalSize,data);
        return pageBean;
    }
}
